<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>fog</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="fofilter.html" title="fofilter" />
    <link rel="next" href="fold.html" title="fold" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">fog</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="fofilter.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="fold.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="fog"></a>
      <div class="titlepage"></div>
      <a id="IndexFog" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">fog</span>
        </h2>
        <p>fog — 
      Audio output is a succession of grains derived from data in a stored function table
          </p>
      </div>
      <div class="refsect1">
        <a id="idp110217552"></a>
        <h2>Description</h2>
        <p>
      Audio output is a succession of grains derived from data in a stored function table <span class="emphasis"><em>ifna</em></span>. The local envelope of these grains and their timing is based on the model of <span class="emphasis"><em>fof</em></span> synthesis and permits detailed control of the granular synthesis.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp110284800"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>fog</strong></span> xamp, xdens, xtrans, aspd, koct, kband, kris, kdur, kdec, \
      iolaps, ifna, ifnb, itotdur [, iphs] [, itmode] [, iskip]</pre>
      </div>
      <div class="refsect1">
        <a id="idp110287056"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iolaps</em></span> -- number of pre-located spaces needed to hold overlapping grain data. Overlaps are density dependent, and the space required depends on the maximum value of <span class="emphasis"><em>xdens</em></span> * <span class="emphasis"><em>kdur</em></span>. Can be over-estimated at no computation cost. Uses less than 50 bytes of memory per <span class="emphasis"><em>iolap</em></span>.
    </p>
        <p>
      <span class="emphasis"><em>ifna</em></span>, <span class="emphasis"><em>ifnb</em></span> -- table numbers of two stored functions. The first is the data used for granulation, usually from a soundfile (<a class="link" href="GEN01.html" title="GEN01"><em class="citetitle">GEN01</em></a>). The second is a rise shape, used forwards and backwards to shape the grain rise and decay; this is normally a sigmoid (<a class="link" href="GEN19.html" title="GEN19"><em class="citetitle">GEN19</em></a>) but may be linear (<a class="link" href="GEN05.html" title="GEN05"><em class="citetitle">GEN05</em></a>).
    </p>
        <p>
      <span class="emphasis"><em>itotdur</em></span> -- total time during which this <span class="emphasis"><em>fog</em></span> will be active. Normally set to p3. No new grain is created if it cannot complete its <span class="emphasis"><em>kdur</em></span> within the remaining <span class="emphasis"><em>itotdur</em></span>.
    </p>
        <p>
      <span class="emphasis"><em>iphs</em></span> (optional) -- initial phase of the fundamental, expressed as a fraction of a cycle (0 to 1). The default value is 0.
    </p>
        <p>
      <span class="emphasis"><em>itmode</em></span> (optional) -- transposition mode. If zero, each grain keeps the <span class="emphasis"><em>xtrans</em></span> value it was launched with. If non-zero, each is influenced by <span class="emphasis"><em>xtrans</em></span> continuously. The default value is 0.
    </p>
        <p>
      <span class="emphasis"><em>iskip</em></span> (optional, default=0) -- If non-zero, skip initialization (allows legato use).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp110300640"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>xamp</em></span> -- amplitude factor. Amplitude is also dependent on the number of overlapping grains, the interaction of the rise shape (<span class="emphasis"><em>ifnb</em></span>) and the exponential decay (<span class="emphasis"><em>kband</em></span>), and the scaling of the grain waveform (<span class="emphasis"><em>ifna</em></span>). The actual amplitude may therefore exceed <span class="emphasis"><em>xamp</em></span>.
    </p>
        <p>
      <span class="emphasis"><em>xdens</em></span> -- density. The frequency of grains per second.
    </p>
        <p>
      <span class="emphasis"><em>xtrans</em></span> -- transposition factor. The rate at which data from the stored function table <span class="emphasis"><em>ifna</em></span> is read within each grain. This has the effect of transposing the original material. A value of 1 produces the original pitch. Higher values transpose upwards, lower values downwards. Negative values result in the function table being read backwards.
    </p>
        <p>
      <span class="emphasis"><em>aspd</em></span> -- Starting index pointer. <span class="emphasis"><em>aspd</em></span> is the normalized index (0 to 1) to table <span class="emphasis"><em>ifna</em></span> that determines the movement of a pointer used as the starting point for reading data within each grain. (<span class="emphasis"><em>xtrans</em></span> determines the rate at which data is read starting from this pointer.)
    </p>
        <p>
      <span class="emphasis"><em>koct</em></span> -- octaviation index. The operation of this parameter is identical to that in <a class="link" href="fof.html" title="fof"><em class="citetitle">fof</em></a>.
    </p>
        <p>
      <span class="emphasis"><em>kband</em></span>, <span class="emphasis"><em>kris</em></span>, <span class="emphasis"><em>kdur</em></span>, <span class="emphasis"><em>kdec</em></span> -- grain envelope shape. These parameters determine the exponential decay (<span class="emphasis"><em>kband</em></span>), and the rise (<span class="emphasis"><em>kris</em></span>), overall duration (<span class="emphasis"><em>kdur</em></span>,) and decay (<span class="emphasis"><em>kdec</em></span> ) times of the grain envelope. Their operation is identical to that of the local envelope parameters in <span class="emphasis"><em>fof</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp110316096"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the fog opcode. It uses the file <a class="ulink" href="examples/fog.csd" target="_top"><em class="citetitle">fog.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp110317952"></a>
          <p class="title">
            <strong>Example 310. Example of the fog opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o fog.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

<span class="comment">;p4 = transposition factor</span>
<span class="comment">;p5 = speed factor</span>
<span class="comment">;p6 = function table for grain data</span>
i1    <span class="op">=</span>	<span class="ohdr">sr</span><span class="op">/</span><span class="opc">ftlen</span>(1) <span class="comment">;scaling to reflect sample rate and table length</span>
a1    <span class="opc">phasor</span> i1<span class="op">*</span>p5 <span class="comment">;index for speed</span>
asigl <span class="opc">fog</span>    .5, 15, p4, a1, 1, 0, .01, .5, .01, 30, 1, 2, p3 		<span class="comment">;left channel</span>
asigr <span class="opc">fog</span>    .4, 25, p4<span class="op">+</span>.2, a1, 1, 0, .01, .5, .01, 30, 1, 2, p3, .5	<span class="comment">;right channel</span>
      <span class="opc">outs</span>   asigl, asigr
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span> 1 0 131072 1 "<span class="stamnt">f</span>ox.wav" 0 0 0
<span class="stamnt">f</span> 2 0 1024 19 .5 .5 270 .5

<span class="stamnt">i</span> 1 0 10 .7  .1
<span class="stamnt">i</span> 1 + 4  1.2  2
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp110322240"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Michael Clark</td>
          </tr>
          <tr>
            <td>Huddersfield</td>
          </tr>
          <tr>
            <td>May 1997</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 3.46</p>
        <p>
      The Csound fog generator is by Michael Clarke, extending his earlier work based on IRCAM's FOF algorithm.
    </p>
        <p>Added notes by Rasmus Ekman on September 2002.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="fofilter.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="fold.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">fofilter </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> fold</td>
        </tr>
      </table>
    </div>
  </body>
</html>
